home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / newsgrp / group99a.txt / 000159_icon-group-sender _Mon Jul 19 08:29:01 1999.msg < prev    next >
Internet Message Format  |  2000-09-20  |  3KB

  1. Return-Path: <icon-group-sender>
  2. Received: (from root@localhost)
  3.     by baskerville.CS.Arizona.EDU (8.9.1a/8.9.1) id IAA05230
  4.     for icon-group-addresses; Mon, 19 Jul 1999 08:28:17 -0700 (MST)
  5. Message-Id: <199907191528.IAA05230@baskerville.CS.Arizona.EDU>
  6. From: "Frank Lhota" <lhotaf@lexma.meitech.com>
  7. To: <icon-group@optima.CS.Arizona.EDU>, "Garry" <memphis@macconnect.com>
  8. Subject: Re: Basename.icn in Library 9.3.2
  9. Date: Mon, 19 Jul 1999 10:39:06 -0400
  10. X-Priority: 3
  11. X-MSMail-Priority: Normal
  12. X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2314.1300
  13. Errors-To: icon-group-errors@optima.CS.Arizona.EDU
  14. Status: RO
  15.  
  16. > I like the new version, it's the Basename that I know and love, but the
  17. behavior has actually changed and the documentation doesn't reflect that (so
  18. I don't know if the behavior is intended or not).  The file documentation
  19. says that
  20. >    #  If no suffix is provided, the portion of the name up to the first
  21. >    #  "." is returned.
  22. >
  23. > I think that that is no longer true and that the new Basename returns the
  24. simple filename, with suffix, if no suffix is specified.
  25. >
  26. > Am I correct? (I'm an Icon newbie and I'm confused as to whether I'm
  27. confused...)
  28. > Is the behavior intended?
  29.  
  30. Yes, that is true. Obviously, the new version has no search for "." if
  31. suffix is undefined or not present. The best way to verify this is by unit
  32. testing, e.g.,
  33.  
  34.     procedure main ( arg )
  35.         write ( basename ( arg [ 1 ], ( arg [ 2 ] | &null ) )
  36.     end
  37.  
  38. > Should the documentation be corrected?
  39. >
  40.  
  41. That all depends on how we want basename to behave. If we actually want the
  42. old behavior, we should correct the procedure instead. I think that the
  43. original idea was to make basename mimic the Unix utility of the same name.
  44. The latest version of basename does seem to match the Unix basename, so if
  45. this is what is desired, we should update the documentation.
  46.  
  47. Here is how I would implement basename:
  48.  
  49. procedure basename(name, suffix)  #: base name of file
  50.    local base
  51.  
  52.    name ? {
  53.       while tab ( upto('/\\:') + 1 )  # get rid of path, if any
  54.       if ( base := tab ( -*\suffix ) ) & =suffix then return base
  55. $ifdef OLD_STYLE
  56.       else return tab ( find ( "." ) | 0 )
  57. $else    # OLD_STYLE
  58.       else return tab ( 0 )
  59. $endif   # OLD_STYLE
  60.       }
  61. end
  62.  
  63. To get the old behavior (cut off everything after the first "." if suffix is
  64. null or not at the end of the name), define the symbol OLD_STYLE. Otherwise,
  65. you'll get the Unix style, i.e. if the suffix is null or not at the end,
  66. return everything past the path part.
  67.  
  68.